<?php
/**
* @desc 用户表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class UserForm extends BaseForm
{
	//邮箱修改
	public function modifyEmail($userId, $email){
		$preg = "/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/";
		if(!preg_match($preg, $email)){
			return false;
		}
		$model = new User;
		return $model->modifyEmail($userId, $email);
	}
	//手机修改
	public function modifyMobile($userId, $mobile){
		$preg = "/^1[3|4|5|8][0-9]\d{4,8}$/";
		if(!preg_match($preg, $mobile)){
			return false;
		}
		$model = new User;
		return $model->modifyMobile($userId, $mobile);
	}
	//修改昵称
	public function modifyNickname($userId, $nickName){
		$preg = "/^[a-z0-9_]{6,30}$/i";
		if(!preg_match($preg, $nickName)){
			return false;
		}
		$model = new User;
		return $model->modifyNickname($userId, $nickName);
	}
	//修改密码
	public function modifyPassword($userId, $passwds){
		$preg = "/^.{6,30}$/i";
		$model = new User;
		$userInfo = $model->getUserInfo($userId);
		if($this->encryPasswd($passwds['passwd']) != $userInfo['password'] || $passwds['passwd'] != $passwds['repasswd']){
			return false;
		}
		if(!preg_match($preg, $passwds['newpasswd'])){
			return false;
		}
		return $model->modifyPasswd($userId, $this->encryPasswd($passwds['newpasswd']));
	}
}
